home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Demos
/
A.D. Software
/
OOFILE
/
Buildable, limited OOFILE
/
samples
/
ooftst02.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-07
|
2KB
|
80 lines
// Copyright 1994 A.D. Software. All Rights Reserved
// OOFTEST2
// This sample tests the database backend by creating a pair of tables
// and storing and retrieving indexed data via traversal paths.
// Simple stream I/O is used to interact with the user.
#include "oofile.hpp"
#include "ooftst02.inc"
int main()
{
cout << "OOFILE Validation Suite - Test 2\n"
<< "Simple test to store some data and retrieve it" << endl
<< "using a relation joining over a field and showing" << endl
<< "iterators on related tables and 1-many relations" << endl << endl;
if (dbConnect::fileExists("ooftst02.db")) {
theDB.openConnection("ooftst02.db");
}
else {
theDB.newConnection("ooftst02.db");
Patients.AddTestData();
}
cout << theDB;
Patients.setSortOrder(Patients.LastName);
Patients.start();
while (Patients.more()) {
cout << Patients.PatientNo << '\t'
<< Patients.LastName << endl;
if (Patients.Visits->count()==0)
cout << "no visits" << endl;
else {
Patients.Visits->start();
while (Patients.Visits->more()) {
cout << '\t' << Patients.Visits->VisitDate << '\t'
<< Patients.Visits->Why << endl;
Patients.Visits->next();
}
}
cout << endl;
Patients.next();
}
cout << endl << "Now repeating the process using a dbView instead of explicitly"
<< endl << "iterating over the related file." << endl;
dbView relatedVisits(Patients.Visits);
relatedVisits << Patients.Visits->VisitDate << Patients.Visits->Why;
Patients.start();
while (Patients.more()) {
cout << Patients.PatientNo << '\t'
<< Patients.LastName << endl;
if (relatedVisits.source()->empty())
cout << "no visits" << endl;
else
cout << relatedVisits << endl;
cout << endl;
Patients.next();
}
/* Coming in v1.2 - search by related fields
cout << "Now finding the Flu sufferers: " << endl;
Patients.search(Patients.Visits->Why=="Flu");
cout << Patients << endl;
*/
Patients.setSortOrder(Patients.Othernames);
cout << "Now dumping the entire database, with patients sorted by Othernames: " << endl << theDB;
cout << "Description of database schema: " << endl;
theDB.describe(cout);
cout << "Test Completed" << endl;
return EXIT_SUCCESS;
}